package com.example.class_manage.Controller;

import com.example.class_manage.Entity.User;
import com.example.class_manage.Mapper.Usermapper;
import com.example.class_manage.Util.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Songxiao
 * @version 1.0
 * @date 2021/11/13 22:58
 */
@Slf4j
@Api(tags = "助教管理接口")
@RestController
@RequestMapping("/")
public class Assistant_Controller {
    @Autowired
    Usermapper usermapper;

    @ApiOperation("删除学生")
    @PostMapping("/deletestudent")
    public JsonData deletestudent(@RequestParam("id") String id) {
        Integer statu = 0;
        statu = usermapper.deleteUser(id);
        return statu != 0 ? JsonData.buildSuccess("删除成功") : JsonData.buildError("删除失败");
    }

    @ApiOperation("增加学生")
    @RequestMapping(value = "/addUser", method = {RequestMethod.POST})
    public JsonData addUser(@RequestBody User u1) {
        //  System.out.println("哈哈哈哈");
        Integer statu = 0;
        statu = usermapper.addUser(u1);
        //System.out.println("此增加的学生"+u1.getName());

        return statu > 0 ? JsonData.buildSuccess("插入成功") : JsonData.buildError("插入失败");
    }

    @GetMapping("/queryUserList")
    @ApiOperation("查找学生列表")
    public JsonData queryUserList(@RequestParam("sclass") String sclass, @RequestParam("grade") String grade) {
        List<User> userList = usermapper.queryUserlist(sclass, grade);
        return userList != null ? JsonData.buildSuccess(userList, "查询成功") : JsonData.buildError("查询失败，请检查");
    }
}
